package com.myproject.myblogserver.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.myproject.myblogserver.service.IVerificationCodeService;

@Controller
@RequestMapping("/verificationCode")
public class VerificationCodeController {
    @Autowired
    private IVerificationCodeService iVerificationCodeService;

    @PostMapping("/send")
    public ResponseEntity<?> sendRegisterEmailCode(@RequestParam String email) {
        try {
            iVerificationCodeService.send(email);
            return ResponseEntity.status(HttpStatus.OK).body("验证码已发送至您的邮箱，请查收！");
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("发送验证码失败！");
        }
    }
}
